//
//  WelcomeViewController.m
//  舟航007机车卫士
//
//  Created by admin on 15/11/9.
//  Copyright (c) 2015年 redoor. All rights reserved.
//

#import "WelcomeViewController.h"
#import "myButton.h"
#import "RootviewConrtoller.h"
#import "LoginViewController.h"
@interface WelcomeViewController ()

@end

@implementation WelcomeViewController
@synthesize scrollview,timer;

- (void)viewDidLoad {
    [super viewDidLoad];
    
//第一次登陆产品的 展示效果
    
    self.view.backgroundColor=[UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self configScrollview];
    
}
-(void)configScrollview{
    scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    scrollview.delegate=self;
    scrollview.pagingEnabled=YES;
    scrollview.contentSize=CGSizeMake(4*SCREEN_WIDTH, SCREEN_HEIGHT);
    scrollview.showsHorizontalScrollIndicator=NO;
    scrollview.showsVerticalScrollIndicator=NO;
    [self.view addSubview:scrollview];
    for(int i=1;i<5;i++){
        UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*(i-1), 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        NSString *imagename=[NSString stringWithFormat:@"adpic_0%i",i];
        imageview.image=[UIImage imageNamed:imagename];
        [scrollview addSubview:imageview];
        if(i<4){
            myButton *btn=[[myButton alloc]initWithFrame:CGRectMake(250*W+SCREEN_WIDTH*(i-1),20+5*H, 40*W, 40*W)];
            [btn setImage:[UIImage imageNamed:@"adicon"] forState:UIControlStateNormal];
            [btn setTitle:@"跳过" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(tapped_step) forControlEvents:UIControlEventTouchUpInside];
            btn.titleLabel.font=[UIFont systemFontOfSize:12];
            btn.titleLabel.textAlignment=NSTextAlignmentCenter;
            [scrollview addSubview:btn];
        }
        else{
            UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*3+(SCREEN_WIDTH-90*W)/2, SCREEN_HEIGHT-60*H, 90*W, 30*H)];
            [btn setImage:[UIImage imageNamed:@"adbtn_01"] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(tapped_step) forControlEvents:UIControlEventTouchUpInside];
            [scrollview addSubview:btn];
        }
    }
    
    //轮播图片自动浏览机制
    timer=[NSTimer scheduledTimerWithTimeInterval:timeinterval target:self selector:@selector(changeOffset) userInfo:nil repeats:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if(scrollview.contentOffset.x==3*SCREEN_WIDTH){
        
        //让定制的轮播时间不起作用
        [timer invalidate];
    }
    else{
        [timer invalidate];
        timer=[NSTimer scheduledTimerWithTimeInterval:timeinterval target:self selector:@selector(changeOffset) userInfo:nil repeats:YES];
    }
}

//引导页自动播放的功能，自动播放下一页面
-(void)changeOffset{
    CGPoint point=scrollview.contentOffset;
    CGFloat x=point.x+SCREEN_WIDTH;
    CGFloat y=point.y;
    
    [scrollview setContentOffset:CGPointMake(x, y) animated:YES];
}
-(void)viewDidDisappear:(BOOL)animated{
    [timer invalidate];
}


//点击跳过到登录界面操作
-(void)tapped_step{
    self.view.window.rootViewController=[LoginViewController new];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
